package org.example.test1;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class main {
    //1.使用字节流完成文件的复制(文件路径和内容自定义)
    public static void main(String[] args) {
        String sourceFilePath = "src/source.txt";
        String targetFilePath = "target.txt";

        try (FileInputStream fis = new FileInputStream(sourceFilePath);
             FileOutputStream fos = new FileOutputStream(targetFilePath)) {

            int bytesRead;
            byte[] buffer = new byte[1024];

            while ((bytesRead = fis.read(buffer)) != -1) {//一直输入直到输入-1
                fos.write(buffer, 0, bytesRead);
            }

            System.out.println("文件复制完成。");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
